<template>
  <div class="container">
    <baleTable :tableData="tableData" :tableHead="tableHead" :isSearch="true" :tableLoading="tableLoading" :page="page"
      @pageSizeChange="pageSizeChange" @handleCurrentChange="handleCurrentChange" @searchMethods="searchMethods"
      @tableSortChange="tableSortChange" @handleRowClick="handleRowClick" ref="baleTable">
      <template #headLeft>
        <el-button size="small" type="primary" @click="showDialog('')">添加</el-button>
            <el-button size="small" type="success" @click="importData()">批量添加</el-button>
        <!-- <div
          class="ml10 tableStats-btn tableStats-btn-active"
          @click="showDialog('')"
        >
          添加
        </div> -->
      </template>
      <template #icon="{ scope }">
        <div @click.stop="">
          <tablePrImg v-if="scope.row.icon" :imgSrc="scope.row.icon" :prImgList="[scope.row.icon]" />
        </div>
      </template>

      <template #video_status="{ scope }">
        {{formatterVideoStatus(scope.row.video_status)}}
      </template>

      <template #consultation_type="{ scope }">
        {{formatterConsultationType(scope.row.consultation_type)}}
      </template>

      <!-- 等级 -->
      <template #skill="{ scope }">
        {{ formmateSkill(scope.row.skill) }}
      </template>
      <template #score1="{ scope }">
        {{ scope.row.score * scope.row.order_count }}
      </template>


      <!--    操作 -->
      <template #tableOperation="{ scope }">
        <!--   <el-button type="danger" size="small" @click="userList(scope.row.id)"
          >用户订单列表</el-button
        > -->
        <!--  <el-button type="info" size="small" @click="addQuality(scope.row.id)"
          >资质申请列表</el-button
        > -->
        <el-button type="success" size="small" @click="resetButton(scope.row.id)" icon="el-icon-key">重置密码</el-button>
        <el-button type="success" size="small" @click="showscore(scope.row.id)">评分明细</el-button>
        <el-button type="primary" size="small" @click="showDialog(scope.row)">编 辑</el-button>
        <el-button type="danger" size="small" @click="deList(scope.row.id)">删除</el-button>
      </template>
    </baleTable>

    <menuDialog ref="dialognur" :subDepartMentArr="subDepartMentArr" @refresh="getTableData"></menuDialog>
    <ImportData @refresh="getTableData" ref="importData" />

    <!--   <userList ref="userListDialog"></userList> -->
    <el-dialog :visible.sync="dialogVisible" title="患者评价列表">
      <!-- 对话框内容 -->
      <el-table :data="tableData1">
          <!-- 患者名称列 -->
          <el-table-column prop="patientName" label="患者名称"></el-table-column>
          <!-- 订单号列 -->
          <el-table-column prop="orderNumber" label="订单号"></el-table-column>
          <!-- 评价时间列 -->
          <el-table-column prop="evaluationTime" label="评价时间"></el-table-column>
          <!-- 评分列 -->
          <el-table-column prop="score" label="评分"></el-table-column>
        </el-table>
      <!-- 对话框底部内容 -->
      <template #footer>
        <span class="dialog-footer">
          <!-- 取消按钮 -->
          <el-button @click="dialogVisible = false">取消</el-button>
          <!-- 确定按钮 -->
          <el-button type="primary" @click="dialogVisible = false">确定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>

import {
  ApigetDoctorList,
  ApiDoctorDel,
  ApiResetPassword,
  ApiSubDepartment
} from "@a/index";
import { tableHead } from "./config";
import menuDialog from "./component/basicDialog.vue";
//获取用户列表数据
/* import userList from "./component/userList.vue"; */
import tablePrImg from "@/components/tablePrImg.vue";
import ImportData from "./component/importData.vue";
export default {

  components: {
    menuDialog,
    tablePrImg,
    ImportData,
    /*   userList, */
  },
  data() {
    return {
      dialogVisible: false,
      // 表格数据
      tableData1: [
        {
          patientName: '张三',
          orderNumber: '20250314001',
          evaluationTime: '2025-03-14 10:00:00',
          score: 4
        },
        {
          patientName: '李四',
          orderNumber: '20250314002',
          evaluationTime: '2025-03-14 11:30:00',
          score: 3
        },
        {
          patientName: '王五',
          orderNumber: '20250314003',
          evaluationTime: '2025-03-14 14:15:00',
          score: 4
        }
      ],
      tableHead,
      tableData: [],
      page: {
        page: 1,
        size: 25,
        total: 0,
      },
      tableLoading: false,
      searchParams: {},
      sortParams: {},
      editFormVisible: false,
      btnLoading: false,
      unitList: [],
      subDepartMentArr: [],
      consultation_typeArr: [
        { name: "全部", code: "0" },
        { name: "图文问诊", code: "1" },
        { name: "视频问诊", code: "2" },
      ],
      isOpenVideo: [
        {
          name: '是', code: '1',
        }, {
          name: '否', code: '0',
        }
      ],

    };
  },
  mounted() {
    this.getTableData();
    this.getSubDepartMent()
  },

  methods: {
    showscore(){
      this.dialogVisible = true
    },

    formatterConsultationType(val) {
      let data = this.consultation_typeArr.find(item => {
        if (item.code == val) {
          return item
        }
      })

      if (data) {
        return data.name
      } else {
        return val
      }
    },
    formatterVideoStatus(val) {
      let data = this.isOpenVideo.find(item => {
        if (item.code == val) {
          return item
        }
      })

      if (data) {
        return data.name
      } else {
        return val
      }
    },


    getSubDepartMent() {
      ApiSubDepartment({ page: 1, size: 999 }).then(res => {
        this.subDepartMentArr = res.data
      })
    },


    importData() {
      this.$refs.importData.show();
    },


    //编辑界面
    onEdit() { },
    showDialog(val) {
      this.$refs.dialognur.show(val);
    },
    /*    userList(id) {
      this.$router.push({
        name: "detail",
        params: { id },
      });
    }, */
    getTableData(params = {}) {
      let postParams = {
        ...params,
        ...this.searchParams,
        ...this.sortParams,
        ...this.page,
      };
      this.tableLoading = true;
      ApigetDoctorList(postParams).then((res) => {
        let { data, page } = res;
        this.tableData = data;
        this.page.total = page.total;
        this.tableLoading = false;
      });
    },
    searchMethods(params) {
      this.searchParams = {};
      this.page.page = 1;
      this.searchParams = params;
      this.getTableData();
    },
    pageSizeChange(val) {
      this.page.size = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      this.page.page = val;
      this.getTableData();
    },
    tableSortChange(params) {
      if (params.sort_str) {
        this.sortParams = { ...this.sortParams, ...params };
      } else {
        delete this.sortParams.sort_str;
        delete this.sortParams.sort_order;
      }
      this.page.page = 1;
      this.getTableData();
    },
    handleRowClick(params) { },
    //shanchu
    deList(id) {
      this.$confirm("是否删除该数据项?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
        type: "warning",
      })
        .then((res) => {
          ApiDoctorDel(id).then((res) => {
            this.$message.success("操作成功！");
            this.getTableData();
          });
        })
        .catch((err) => { });
    },
    resetButton(id) {
      this.$confirm("是否确认重置密码?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
        type: "warning",
      })
        .then((res) => {
          ApiResetPassword(id).then((res) => {
            this.$alert("重置成功，该员工初始密码为：Hlwyy@123456", "提示", {
              confirmButtonText: "确定",
              callback: (action) => { },
            });
            this.getTableData();
          });
        })
        .catch((err) => { });
    },

  },
  filters: {},
};
</script>

<style lang="less" scoped>
/deep/.el-dialog{
  max-height: 96vh !important;
  overflow: auto;
}
</style>
